home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Viewers / VideoStreamV1.0 / Source / AVIView.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.0 KB  |  107 lines

  1. /*
  2.  * Copyright 1994, Black Adder Research, Inc.  This source code may be
  3.  * redistributed and modified with one restriction - do not claim that 
  4.  * you wrote it.
  5.  *
  6.  * Black Adder Research, Inc.
  7.  * 730 Norell Ave. North
  8.  * Stillwater, MN  55082
  9.  * 
  10.  */
  11.  
  12.  
  13. #import "AVIView.h"
  14. #import <appkit/appkit.h>
  15.  
  16. @implementation AVIView : View
  17.  
  18. - initSize: (const NXSize *) aSize
  19. {
  20.     NXRect imageRect;
  21.     id retVal = nil;
  22.  
  23.     NXSetRect(&imageRect, 0.0, 0.0, aSize->width, aSize->height);
  24.     [super initFrame:&imageRect];
  25.     strcpy(aviFile, "");
  26.     if((theData = (unsigned char *)malloc(3 * (int) (aSize->width * aSize->height))) != NULL) {
  27.         if((theBitmap = [[NXBitmapImageRep alloc] initData:theData
  28.             pixelsWide: (int) aSize->width
  29.             pixelsHigh: (int) aSize->height
  30.             bitsPerSample: 8
  31.             samplesPerPixel: 3
  32.             hasAlpha: NO
  33.             isPlanar: NO
  34.             colorSpace: NX_RGBColorSpace
  35.             bytesPerRow: 0
  36.             bitsPerPixel: 0]) != nil) {
  37.     
  38.                 retVal = self;
  39.         }
  40.     }
  41.     return(retVal);
  42. }
  43.  
  44.  
  45. - runFromFile: (char *) AVIFile
  46. {
  47.     strcpy(aviFile, AVIFile);
  48.     [self runAgain];
  49.     return(self);
  50. }
  51.  
  52.  
  53. - runAgain
  54. {
  55.     char command[256];
  56.     int numFrPix;
  57.     BOOL shouldLoop = YES;
  58.     FILE *ifp;
  59.  
  60.     if (strcmp(aviFile, "") != 0) {
  61.         numFrPix = 3 * [theBitmap pixelsWide] * [theBitmap pixelsHigh];
  62.         sprintf(command, "%s/aviDecode %s", [[NXBundle mainBundle] directory], aviFile);
  63.         if ((ifp = popen(command, "r")) != NULL) {            
  64.             fread(theData, 1, 2*sizeof(int), ifp);    /* skip width and height */
  65.             [self lockFocus];
  66.             while(shouldLoop) {
  67.                 if(NXUserAborted()) {
  68.                     NXResetUserAbort();
  69.                     if(NX_ALERTDEFAULT == NXRunAlertPanel("AVIStream", 
  70.                             "Stop Playback?", "Yes", "No", NULL) ) {
  71.                         shouldLoop = NO;
  72.                         break;
  73.                     }
  74.                 }
  75.                 if(fread(theData, 1, numFrPix, ifp) != numFrPix) {
  76.                     shouldLoop = NO;
  77.                     break;
  78.                 }
  79.                 else {
  80.                     [theBitmap draw];
  81.                     NXPing();
  82.                 }
  83.             }
  84.             [self unlockFocus];
  85.             pclose(ifp);
  86.         }
  87.     }
  88.     return(self);
  89. }
  90.  
  91.  
  92. - drawSelf:(const NXRect *)rects :(int)rectCount
  93. {
  94.     [theBitmap draw];
  95.     return self;
  96. }
  97.  
  98.  
  99. - free
  100. {
  101.     free(theData);
  102.     [theBitmap free];
  103.     return [super free];
  104. }
  105.  
  106. @end
  107.